﻿using AntdUI;
using System.Drawing.Drawing2D;
using WenAntdUI.Helps;

namespace WenAntdUI
{
    public partial class WenForm : AntdUI.Window
    {
        public WenForm()
        {

#if DEBUG
            if (Helper.IsDesign)
            {
                this.FormBorderStyle = FormBorderStyle.None;
            }
#endif

            this.MaximizedBounds = Screen.PrimaryScreen.WorkingArea;
            this.BackColor = SystemColors.Control;

            //this.StartPosition = FormStartPosition.CenterScreen;

            this.header = new AntdUI.PageHeader()
            {
                Height = 35,
                Dock = DockStyle.Top,
                ShowButton = true,
                ShowIcon = true,
                DividerShow = true,
                DividerMargin = 3,
            };
            this.Controls.Add(header);


            #region 皮肤设置
            AntdHelp.SetTheme(this, btnTheme);

            btnTheme = new AntdUI.Button()
            {
                IconSvg = "MoonOutlined",
                Dock = DockStyle.Right,
                Size = new Size(40, 40),
                Ghost = true,
                Visible = IsShowThemeButton,
            };
            this.header.Controls.Add(btnTheme);

            btnTheme.Click += (s, e) =>
            {
                AntdHelp.SetTheme(this, btnTheme, !AntdUI.Config.IsDark, Settings.AppSettings.Get<Color>("ThemeColor"));
            };
            #endregion
        }

        #region 私有属性
        private readonly AntdUI.PageHeader header;
        private readonly AntdUI.Button btnTheme;
        private bool isShowThemeButton = false;
        #endregion

        #region 重置属性默认

        /// <summary>
        /// 窗口样式
        /// </summary>
        [DefaultValue(FormBorderStyle.None)]
        public new FormBorderStyle FormBorderStyle { get => base.FormBorderStyle; set => base.FormBorderStyle = value; }
        /// <summary>
        /// 最大化按钮
        /// </summary>
        public new bool MaximizeBox { get => base.MaximizeBox; set { base.MaximizeBox = value; header.MaximizeBox = value; } }
        /// <summary>
        /// 最小化按钮
        /// </summary>
        public new bool MinimizeBox { get => base.MinimizeBox; set { base.MinimizeBox = value; header.MinimizeBox = value; } }
        /// <summary>
        /// 是否显示图标
        /// </summary>
        public new bool ShowIcon { get => base.ShowIcon; set { header.ShowIcon = value; base.ShowIcon = value; } }
        /// <summary>
        /// 文本标题
        /// </summary>
        public new string Text { get => base.Text; set { base.Text = value; header.Text = value; } }

        /// <summary>
        /// 默认启动位置
        /// </summary>
        [DefaultValue(FormStartPosition.CenterScreen)]
        public new FormStartPosition StartPosition { get => base.StartPosition; set => base.StartPosition = value; }
        /// <summary>
        /// 图标
        /// </summary>
        public new Image? Icon
        {
            get => header.Icon;
            set
            {
                if (value != null)
                {
                    var bitmap = new Bitmap(value);
                    IntPtr hicon = bitmap.GetHicon();
                    var icon = System.Drawing.Icon.FromHandle(hicon);
                    base.Icon = icon;
                }
                header.Icon = value;
            }
        }
        #endregion

        #region 自定义公开属性
        /// <summary>
        /// 是否显示按钮
        /// </summary>
        [Description("是否显示标题栏按钮")]
        [Category("外观")]
        [DefaultValue(false)]
        public bool ShowButton { get => header.ShowButton; set => header.ShowButton = value; }

        [Description("副标题")]
        [Category("外观")]
        [DefaultValue(null)]
        [Localizable(true)]
        public string? SubText { get => header.SubText; set => header.SubText = value; }

        /// <summary>
        /// 标题
        /// </summary>
        [Description("标题控件")]
        [Category("外观")]
        public PageHeader Header => this.header;

        [Description("是否显示皮肤设置按钮")]
        [Category("外观")]
        [DefaultValue(false)]
        public bool IsShowThemeButton { get => isShowThemeButton; set { isShowThemeButton = value; this.btnTheme.Visible = value; } }

        /// <summary>
        /// 顶部右侧区域
        /// </summary>
        public Control.ControlCollection TopControls => header.Controls;
        #endregion


        #region 私有方法


        #endregion

        #region 重写属性

        protected override void OnPaint(PaintEventArgs e)
        {
            e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
            e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
            e.Graphics.CompositingQuality = CompositingQuality.HighQuality;
            base.OnPaint(e);
        }

        #endregion
    }
}
